<!-- 领料-已出库 -->
<template>
  <div>
    <div ref="search" class="app-search">
      <el-row class="mt10" type="flex">
        <Search :data="selections" :attribute="'createdTime'" @dateChange="handleDateChange" @change="handleTypeChange" />
        <el-form ref="searchFormRef" :model="searchForm" :inline="true">
          <el-form ref="searchFormRef" :model="searchForm" :inline="true">
          <!-- <el-form-item label="选择顾客：" class="marginLeft">
            <el-select v-model="searchForm.value" placeholder="请选择">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item> -->
          </el-form>
        </el-form>
      </el-row>
    </div>
    <!-- 表单区域  -->
    <div class="box-show marginTop">
      <el-table v-loading="loading" :data="haveOutboundList" border :row-class-name="tableColor" :height="innerHeight">
        <el-table-column label="领料单号" prop="receiveCode" :show-overflow-tooltip="true" />
        <el-table-column label="申请/开单人" prop="receiveUsr" :show-overflow-tooltip="true" />
        <el-table-column label="顾客" prop="customerName" :show-overflow-tooltip="true" />
        <el-table-column label="科室/部门" prop="deptName" :show-overflow-tooltip="true" />
        <el-table-column label="出库时间" prop="outStockDate" align="center" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.outStockDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="经办人" prop="processor" :show-overflow-tooltip="true" />
        <el-table-column label="操作" min-width="120">
          <template slot-scope="scope">
            <el-button type="text" @click="detailsBtn(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination :page-num="params.page" :page-size="params.pageSize" :on-change="handlePaginationChange" :total="total" />
    </div>
    <!-- 详情 -->
    <Dialog :title="title" :visible.sync="visible" :reveal="false" :loading="loading" @close="handleClose">
      <!-- <div class="headStyle">
        <span>领料单号：{{ haveOutbound.receiveCode }}</span><span>申请/开单人：{{ haveOutbound.receiveUsr }}</span><span>科室/部门：{{ haveOutbound.deptName }}</span><span>顾客：{{ haveOutbound.customerName }}</span>
      </div> -->
      <el-row>
        <el-col :span="12">领料单号：{{ haveOutbound.receiveCode }}</el-col>
        <el-col :span="12">申请/开单人：{{ haveOutbound.receiveUsr }}</el-col>
        <el-col :span="12">科室/部门：{{ haveOutbound.deptName }}</el-col>
        <el-col :span="12">顾客：{{ haveOutbound.customerName }}</el-col>
      </el-row>
      <el-table v-loading="loading" :data="haveOutboundTable" border :row-class-name="tableColor">
        <el-table-column label="名称" prop="name" :show-overflow-tooltip="true" />
        <el-table-column label="规格" prop="specl" :show-overflow-tooltip="true" />
        <el-table-column label="单位" prop="unit" :show-overflow-tooltip="true" />
        <el-table-column label="出库数量" prop="receiveCount" :show-overflow-tooltip="true" />
        <el-table-column label="操作" min-width="120">
          <template slot-scope="scope">
            <el-button type="text" @click="batchOutboundBtn(scope.row)">批次详情</el-button>
          </template>
        </el-table-column>
      </el-table>
    </Dialog>
    <!-- 批次出库详情 -->
    <Dialog :title="titleTwo" :visible.sync="visibleTow" :reveal="false" :loading="loading">
      <!-- <div class="headStyle"><span>名称：{{ batchDetails.name }}</span><span>规格：{{ batchDetails.specl }}</span><span>单位：{{ batchDetails.unit }}</span><span>出库数量：{{ batchDetails.receiveCount }}</span>
      </div> -->
      <el-row>
        <el-col :span="12">名称：{{ batchDetails.name }}</el-col>
        <el-col :span="12">规格：{{ batchDetails.specl }}</el-col>
        <el-col :span="12">单位：{{ batchDetails.unit }}</el-col>
        <el-col :span="12">出库数量：{{ batchDetails.receiveCount }}</el-col>
      </el-row>
      <el-table v-loading="loading" :data="batchDetailsTable" border :row-class-name="tableColor">
        <el-table-column label="批次号" prop="inventoryBatch" :show-overflow-tooltip="true" />
        <el-table-column label="供应商" prop="inventorySupplier" :show-overflow-tooltip="true" />
        <el-table-column label="仓库" prop="warehouseName" :show-overflow-tooltip="true" />
        <el-table-column label="到期时间" prop="inventoryExpiredDate" :show-overflow-tooltip="true" />
        <el-table-column label="出库数量" prop="outStockCount" :show-overflow-tooltip="true" />
      </el-table>
    </Dialog>
  </div>
</template>
<script>
import Search from "@/components/Search";
import { selections } from "@/config";
import { tableColor } from '@/utils/common.js';
import Dialog from "@/components/Dialog/index";
window.onbeforeunload = event => {
  window.scrollTo(0, 0); // 每次刷新，滚动条在页面最上面
};
export default {
  components: {
    Search,
    Dialog,
  },
  data() {
    return {
      selections,
      tableColor,
      innerHeight: null,
      searchForm: {},
      options: [],
      params: {
        page: 1,
        pageSize: this.$store.state.commonsettings.maxPageSize,
      },
      total: 0,
      haveOutboundList: [],
      requestInfo: {
        drugType: '领料',
        receiveStatus: '已出库',
      },
      haveOutbound: {},
      haveOutboundTable: [],
      batchDetails: {},
      batchDetailsTable: [],
      title: "",
      // testBtn: "",
      visible: false, // 出库
      titleTwo: "",
      // testBtnTwo: "",
      visibleTow: false, // 批次出库
      loading: false,
    };
  },
  mounted() {
    this.getHaveOutboundList();
    var topHeight = (this.$refs.search.clientHeight + 160 + 125);
    var winHeight = document.body.clientHeight || document.documentElement.clientHeight;
    this.innerHeight = winHeight - topHeight;
  },
  methods: {
    async getHaveOutboundList() {
      this.loading = true;
      const res = await this.$api['warehouse/dispensing/outboundlist']({ ...this.params, query: this.requestInfo });
      this.loading = false;
      if (res.code !== 200) return this.$message.error('查询已出库列表失败！');
      this.haveOutboundList = res.data.result;
      this.total = res.data.total;
    },
    handlePaginationChange(val) {
      this.params = { page: val.pageNum, pageSize: val.pageSize };
      this.getOutboundList();
    },
    // 详情
    async detailsBtn(row) {
      this.haveOutbound = row;
      this.title = "物品出库详情";
      // this.testBtn = "提 交";
      this.visible = true;
      const res = await this.$api['warehouse/dispensing/druglist']({
        query: { receiveId: row.id },
      });
      if (res.code !== 200) return this.$message.error('查询详情列表失败！');
      this.haveOutboundTable = res.data.result;
    },
    // 批次出库详情
    async batchOutboundBtn(row) {
      this.batchDetails = row;
      this.titleTwo = "物品批次出库详情";
      // this.testBtnTwo = "确 认";
      this.visibleTow = true;
      this.loading = true;
      const res = await this.$api['warehouse/dispensing/haveBatchDrugdetails']({
        query: { receiveId: row.receiveId, materialMedicineId: row.drugId },
      });
      this.loading = false;
      if (res.code !== 200) return this.$message.error('查询批次详情列表失败！');
      this.batchDetailsTable = res.data.result;
    },
    handleClose() {
      this.visible = false;
    },
    // 顶部时间筛选
    handleDateChange(val) {
      this.requestInfo.timeType = val.timeType;
      this.requestInfo.createdTime = val.createdTime;
      this.getHaveOutboundList();
    },
    handleTypeChange(val) {
      this.requestInfo.timeType = val.timeType;
      this.requestInfo.createdTime = val.createdTime;
      this.getHaveOutboundList();
    },
  },
};
</script>
<style lang="scss" scoped>
</style>
